﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Text.RegularExpressions;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using RazorEngine;
using System.Reflection;
using System.Collections.Generic;
using System.Configuration;

namespace UnitTestProject {
    [TestClass]
    public class Factory {
        //生成固定的vm 实体和 ef上下文
        [TestMethod]
        public void GenerateVmEntitysCtx() {
            var entitypath = Configh.Path_Vmentitys;
            var ctxpath = Configh.Path_Vmctx;
            Gh.GenerateEntitysCtx(entitypath, ctxpath, Gh.GenerateEntityBase(Properties.Resources.vm, true), Gh.GenerateEntityCtx(Properties.Resources.vm, "Vmctx"));
            Gh.GenerateVmh();
        }
        //生成业务实体和 业务实体的ef上下文
        [TestMethod]
        public void GenerateBizEntitysCtx() {
            var entitypath = Configh.Path_Caseentitys;
            var ctxpath = Configh.Path_Casectx;
            var dbsql = File.ReadAllText(Configh.Path_CaseDb);
            dbsql = string.IsNullOrEmpty(dbsql) ? Properties.Resources.casedb:dbsql;
            Gh.GenerateEntitysCtx(entitypath, ctxpath, Gh.GenerateEntityBase(dbsql), Gh.GenerateEntityCtx(dbsql, "Casectx"));
        }
        [TestMethod]
        public void GenerateUiContainer() {
            var path = string.Format("{0}Core",Configh.Path_Root);
            var ns = path.Split('\\').Last();
            //Console.WriteLine("{0},{1}",path,ns);
            path = string.Format("{0}\\UiContainer.cs", path);
            
            Gh.GenerateUiContainer(path,ns);
        }
        [TestMethod]
        public void GenerateVmStyle() {
            var proxyns = Regex.Match(Configh.Path_VmStyleConverter, @"(?<=\\)\w+\.?\w+(?=\\VmStyleConverter.cs)").Value;
            var x1 = Regex.Match(Configh.Path_Vmentitys, ".*(?=Vmentitys.cs)").Value;
            var x2 = Regex.Match(Configh.Path_Vmentitys, @"(?<=\\)\w+\.?\w+(?=\\Vmentitys.cs)").Value;
            var entitypath = string.Format("{0}bin\\Release\\{1}.dll", x1, x2);
            var core = Regex.Match(Configh.Path_Vmh, @"(?<=\\)[^\\]*(?=\\Vmh.cs)").Value;
            //
            Gh.CreateVmStyleConverter(proxyns, core, Configh.Path_VmStyleConverter);
            Gh.CreateVmUiStyle(proxyns, entitypath, Configh.Path_VmUiStyle);
        }
        [TestMethod]
        public void GenerateConfig() {
            var x1 = Regex.Match(Configh.Path_Vmentitys, ".*(?=Vmentitys.cs)").Value;
            var x2 = Regex.Match(Configh.Path_Vmentitys, @"(?<=\\)\w+\.?\w+(?=\\Vmentitys.cs)").Value;
            var entitypath = string.Format("{0}bin\\Release\\{1}.dll", x1, x2);
            var core = Regex.Match(Configh.Path_Vmh, @"(?<=\\)[^\\]*(?=\\Vmh.cs)").Value;
            var np = Regex.Match(Configh.Path_VmStyleConverter, @"(?<=\\)[^\\]*(?=\\VmStyleConverter.cs)").Value;
            var isd = bool.Parse(Configh.IsD);
            //Console.WriteLine(entitypath);//ok
            Gh.GenerateConfigSelector(entitypath, np, core,Configh.Path_Config,isd);
        }
        //
    }
}
